<template>
  <el-dialog
    :before-close="cancel"
    :visible.sync="value">
    <template slot="title">
      批量审核
    </template>
    <div class="tip"> <i class="el-icon-warning"></i> 当前勾选的数据，请选择您要进行操作的方式。</div>
    <el-form :model="form" ref="refForm" :label-width="'150px'" :rules="refRules">
      <el-form-item prop="remark" label="备注">
        <el-col :span="16">
          <el-input v-model="form.remark"></el-input>
        </el-col>
      </el-form-item>     
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="warning"  @click="auditSuccess(1)">全部初审通过</el-button>
      <el-button type="warning"  @click="auditSuccess(2)">全部终审通过</el-button>
      <el-button type="danger" @click="innerVisible = true">拒绝发放</el-button>
    </div>

     <el-dialog
      width="50%"
      title="内层 Dialog"
      :visible.sync="innerVisible"
      append-to-body>
      <template slot="title">
        拒绝发放
      </template>
       <el-form :model="form" ref="refForm" :label-width="'150px'" :rules="refRules">
      <el-form-item prop="remark" label="备注">
        <el-col :span="16">
          <el-input v-model="form.remark"></el-input>
        </el-col>
      </el-form-item>     
    </el-form>
    <div class="tip inner-tip">拒绝发放后，代理则无法获取本月的代理佣金。</div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="innerVisible = false">取消</el-button>
      <el-button type="primary" @click="auditRefuse">确定</el-button>
    </div>
    </el-dialog>
  </el-dialog>

</template>

<script>
  import {updateApproveFirst,updateApproveSecond} from '@/services/api/commission'
  import {form} from '@/build'

  export default {
    name: "commission-audit-dialog",
    props:['value','ids'],
    mixins:[form],
    data(){
      return{
        innerVisible: false,
        noticeStr: '',
        form:{
          status: undefined,
          ids: this.ids.join(","),
          remark:''
        },
        step:0,
        refRules:{
          refuse:{required:true,message:'拒绝发放理由为必填'},
          remark:{required:true,message:'审核备注为必填'},
        }
      }
    },
    methods:{
      auditSuccess(step){
        this.form.status = 1;
        this.step=step
        // this.submitMultipleStatus()
        this.doSave({action:this.step === 1 ? 'ApproveFirst' : 'ApproveSecond' , form: 'refForm'})
      },
      cancel(){
        this.$emit('input', false);
      },
      auditRefuse(){        
        this.form.status = 2
        this.doSave({action:this.step === 1 ? 'ApproveFirst' : 'ApproveSecond' , form: 'refForm'})
      },
    },    
    mounted(){
      this.bindSave(updateApproveFirst,'ApproveFirst','form',{
        afterSuccess:data=>{
          this.$parent.getAll()
          this.cancel();
        }
      })
      this.bindSave(updateApproveSecond,'ApproveSecond','form',{
         afterSuccess:data=>{
          this.$parent.getAll()
          this.cancel();
        }
      })
    }
  }
</script>

<style lang="scss" scoped>
.tip{
  text-align: center;
  font-size: 16px;
  padding: 10px;
  .el-icon-warning{
    color: orange;
  }
}
.inner-tip{
  color: red;
}
</style>
